package com.inews.business.web;

import java.util.Map;

import javax.servlet.ServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.inews.base.mapper.JsonMapper;
import com.inews.base.utils.InewsUtils;
import com.inews.base.utils.Servlets;
import com.inews.base.vo.ExtData;
import com.inews.business.service.BatchLogService;
import com.inews.business.vo.BatchLogVo;

@Controller
@RequestMapping("/batchLog")
public class BatchLogController {
	
	@Autowired
	private BatchLogService service;
	
	
	/**
	 * 分页查询批处理记录信息.
	 *
	 * @param request the request
	 * @param pageNumber the page number
	 * @param sort the sort
	 * @return the object
	 */
	@RequestMapping("findBatchLogPage")
	@ResponseBody
	public Object findBatchLogPage(ServletRequest request, @RequestParam(value = "page", defaultValue = "1") int pageNumber, String sort){
		Pageable page = Servlets.buildPageRequest(pageNumber, sort);
		Map<String, Object> searchParams = Servlets.getParametersStartingWith(request, "search_");
		ExtData<BatchLogVo> extData = service.findBatchLogPage(searchParams, page);
		String json = JsonMapper.nonEmptyMapper().toJson(extData);
		return json;
	}
	
	
	/**
	 * 执行批处理.
	 *
	 * @param vo the vo
	 * @return the object
	 */
	@RequestMapping("executeBatch")
	@ResponseBody
	public Object executeBatch(){
		ExtData<String> extData = service.executeBatch(InewsUtils.getUserInfo());
		String json = JsonMapper.nonEmptyMapper().toJson(extData);
		return json;
	}
	
	
}
